import {categoryTree, list}  from '@/Json/categoryTree.js'
export default [
    {
        url: 'product/List',
        method: 'post',
        t(req) {
            const { current, size, productCategory,categoryId,name } = JSON.parse(req.body)
            // console.log(current, size, productCategory,categoryId)
            // console.log((current-1)*10)
            let maplist = []
            let filter=(condition,data)=>{
                console.log(condition)
                return data.filter( item => {
                    return Object.keys( condition ).every( key => {
                       return String( item[ key ] ).toLowerCase().includes( String( condition[ key ] ).trim().toLowerCase() ) } )
                 } )
            }
            var condition={productCategory,name};
            maplist = filter(condition,list);
            return {
                code: 0,
                maplist,
                data: maplist.slice((current-1)*10,current*size),
                current: current,
                pageSize: size,
                totalpage: Math.ceil(maplist.length/size),
                total: maplist.length,
                success: true,
                message: '查询成功',
            }
        }
    },
     {
        url: 'product/category',
        method: 'post',
        t(req) {
            return {
                code: 0,
                data: categoryTree,
                success: true
            }
           
        }
    },
    {
        url: 'product/add',
        method: 'post',
        t(req) {
            console.log(JSON.parse(req.body))
            const { data} = JSON.parse(req.body)
            console.log(data)
            return {
                code: 0,
                data: categoryTree,
                success: true
            }
           
        }
    }
]
